package com.suda.controller;

import com.github.pagehelper.PageInfo;
import com.suda.pojo.OrderRoute;
import com.suda.service.OrderRouteService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:zhuyongjie
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/orderRoute")
@CrossOrigin
public class OrderRouteController {

    @Autowired
    private OrderRouteService orderRouteService;

    /***
     * OrderRoute分页条件搜索实现
     * @param orderRoute
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) OrderRoute orderRoute, @PathVariable  int page, @PathVariable  int size){
        //调用OrderRouteService实现分页条件查询OrderRoute
        PageInfo<OrderRoute> pageInfo = orderRouteService.findPage(orderRoute, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * OrderRoute分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用OrderRouteService实现分页查询OrderRoute
        PageInfo<OrderRoute> pageInfo = orderRouteService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param orderRoute
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<OrderRoute>> findList(@RequestBody(required = false) OrderRoute orderRoute){
        //调用OrderRouteService实现条件查询OrderRoute
        List<OrderRoute> list = orderRouteService.findList(orderRoute);
        return new Result<List<OrderRoute>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用OrderRouteService实现根据主键删除
        orderRouteService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改OrderRoute数据
     * @param orderRoute
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody OrderRoute orderRoute, @PathVariable String id){
        //设置主键值
        orderRoute.setRouteId(id);
        //调用OrderRouteService实现修改OrderRoute
        orderRouteService.update(orderRoute);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增OrderRoute数据
     * @param orderRoute
     * @return
     */
    @PostMapping
    public Result add(@RequestBody OrderRoute orderRoute){
        //调用OrderRouteService实现添加OrderRoute
        orderRouteService.add(orderRoute);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询OrderRoute数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<OrderRoute> findById(@PathVariable String id){
        //调用OrderRouteService实现根据主键查询OrderRoute
        OrderRoute orderRoute = orderRouteService.findById(id);
        return new Result<OrderRoute>(true,StatusCode.OK,"查询成功",orderRoute);
    }

    /***
     * 查询OrderRoute全部数据
     * @return
     */
    @GetMapping
    public Result<List<OrderRoute>> findAll(){
        //调用OrderRouteService实现查询所有OrderRoute
        List<OrderRoute> list = orderRouteService.findAll();
        return new Result<List<OrderRoute>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
